package com.rxtxdemo.rxtxdemo.applicationevent.listener;


import com.rxtxdemo.rxtxdemo.applicationevent.even.ComRegisterEvent;
import com.rxtxdemo.rxtxdemo.demo.MyLister;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

//执行指令策略3
@Service
@Slf4j
public class J3Service {
    @EventListener
    @Async
    public void onApplicationEvent(ComRegisterEvent arg0) throws InterruptedException {
        MyLister.sum++;
        // System.out.println("开始延迟J333333:"+ Thread.currentThread().getId());
        Thread.sleep(1000);
//        Map m=(Map)arg0.getSource();
//        int three=Integer.parseInt(m.get("three").toString());
//        if(three>20){
//            Thread.sleep(5000);
//            m.put("one","false");
//            log.info("J3设备开启修改J1设备关闭！！！！");
//        }
//
//        m.put("two", String.valueOf(RandomUtil.randomInt(1,30)));
//        m.put("three",String.valueOf(RandomUtil.randomInt(1,30)));

//        System.out.println("异步执行！！！J33333:"+ Thread.currentThread().getId());
//        System.out.println("线程id：J3333333333333333333333333" + Thread.currentThread().getId());
//        System.out.println("线程名称：" + Thread.currentThread().getName());

        System.out.println("J3服务接到通知，给 " + arg0.getSource());
    }

}
